<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fy.model.Student" %>
<%@ page import="com.fy.model.Page" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>学生信息列表</title>
		<meta name="keywords" content="学生,信息,管理,系统">
		<meta name="description" content="学生信息管理系统">
		<%@ include file="../public/head.jspf"%>
	</head>
	<body>
		<div class="box">
			<h1>学生信息管理系统<a class="back">返回</a></h1>
			<div class="content">
				<div id="data">
					<table id="datalist">
						<caption>全部学生信息如下</caption>
						<tr>
							<th>学号</th>
							<th>姓名</th>
							<th>年龄</th>
							<th>性别</th>
							<th>专业</th>
							<th>
								操作
								<input type="button" value="添加" class="btn blue" onclick="location.href='students?methodName=-1'" />
							</th>
						</tr>
						<%
							response.setCharacterEncoding("UTF-8");
							request.setCharacterEncoding("UTF-8");
							Page pager=(Page)request.getAttribute("pager");
							List<Student> subResult=(List<Student>)request.getAttribute("subResult");
							  if(!subResult.isEmpty()){
							  for(int i=0;i<subResult.size();i++){
							       Student st=subResult.get(i);
							       out.println("<tr>");
			    	    			out.println("							<td>" + st.getId() + "</td>");
			    	    			out.println("							<td>" + st.getName() + "</td>");
			    	    			out.println("							<td>" + st.getAge() + "</td>");
			    	    			out.println("							<td>" + st.getGender() + "</td>");
			    	    			out.print("							<td>" + st.getMajor() + "</td>");
						%>
		     				<td class="td_modi">
								<input type="button" value="删除" class="btn red"
									onclick="if(confirm('确定要删除此记录吗？')==true)location.href='students?methodName=2&id=<%=st.getId()%>'" />
								<input type="button" value="修改" class="btn green"
									onclick="location.href='students?methodName=4&id=<%=st.getId()%>'" />
							</td>
					    <% 
					    			out.print("</tr>\n						");
								}
							}
					     %>
	     			</table>
	     			<div id="pages">
     					<a href="#">总<%=pager.getTotalRecord() %>条记录</a>
					    <a href="#">总<%=pager.getTotalPage() %>页</a>
					    <a href="#" class="current_page">当前<%=pager.getCurrentPage()+1 %>页</a>
					    <a href="#">每页<%=pager.getPageSize() %>条</a>
					    <%
				     		int last = pager.getCurrentRecord() - pager.getPageSize();
				     		int next = pager.getCurrentRecord() + pager.getPageSize();
				     		int currentRecord;
				     		if (last < 0) 
				     			out.println("<a href='#'>首页</a>");
				     		else
				     			out.print("<a href='students?currentRecord=" + last + "&methodName=1'>上一页</a>");
				     		if (next >= pager.getTotalRecord())
				     			out.println("<a href='#'>尾页</a>");
				     		else
				     			out.print("<a href='students?currentRecord=" + next + "&methodName=1'>下一页</a>");
				     	%>
	                </div>
				    <form action="students" method="post">
				    	<table id="datalist">
					    	<caption>按学号/姓名查询<input type="hidden" name="methodName" value="5"/></caption>
					    	<tr>
								<td>学号：</td>
								<td><input type="text" name="id"  value="" title="学号必须为数字" /></td>
							</tr>
							<tr>
								<td>姓名：</td>
								<td><input type="text" name="name" value="" title="" /></td>
							</tr>
							<tr>
								<td colspan="2">
									<input type="submit" class="btn green" value="查询" />
								</td>
							</tr>
						</table>
					</form>
    			</div>
			</div>
		</div>
	</body>
</html>